home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
WINPROGS
/
UPC12BS1.ZIP
/
UUCP
/
UUCP.C
next >
Wrap
C/C++ Source or Header
|
1993-10-03
|
27KB
|
672 lines
/*--------------------------------------------------------------------*/
/* u u c p . c */
/* */
/* UUCP lookalike for IBM PC. */
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* Changes Copyright (c) 1989-1993 by Kendra Electronic */
/* Wonderworks. */
/* */
/* All rights reserved except those explicitly granted by the */
/* UUPC/extended license agreement. */
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* RCS Information */
/*--------------------------------------------------------------------*/
/*
* $Id: uucp.c 1.9 1993/10/03 20:43:08 ahd Exp $
*
* Revision history:
* $Log: uucp.c $
* Revision 1.9 1993/10/03 20:43:08 ahd
* Normalize comments to C++ double slash
*
* Revision 1.8 1993/10/02 19:07:49 ahd
* Use 0644 permissions on files
*
* Revision 1.7 1993/09/20 04:48:25 ahd
* TCP/IP support from Dave Watt
* 't' protocol support
* OS/2 2.x support (BC++ 1.0 for OS/2)
*
* Revision 1.6 1993/08/02 03:24:59 ahd
* Further changes in support of Robert Denny's Windows 3.x support
*
* Revision 1.5 1993/07/31 16:27:49 ahd
* Changes in support of Robert Denny's Windows support
*
* Revision 1.4 1993/04/11 00:35:46 ahd
* Global edits for year, TEXT, etc.
*
* Revision 1.3 1993/04/05 04:35:40 ahd
* Use timestamp/file size information returned by directory search
*
* Revision 1.2 1992/12/11 12:45:11 ahd
* Normalize paths for files read
*
*/
/*--------------------------------------------------------------------*/
/* */
/* Change history: */
/* */
/* 02/08/81 H.A.E.Broomhall */
/* Hacked for UUPC/extended 1.09c */
/* 04/27/91 Drew Derbyshire */
/* Modified for UUPC/extended 1.10a */
/* 09/26/91 Mitch Mitchell */
/* Support for UUX */
/* 01/26/92 Drew Derbyshire */
/* Various comment and error message clean up */
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* system include files */
/*--------------------------------------------------------------------*/
#include <ctype.h>
#include <direct.h>
#include <fcntl.h>
#include <io.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef _Windows
#include <windows.h>
#endif
/*--------------------------------------------------------------------*/
/* UUPC/extended include files */
/*--------------------------------------------------------------------*/
#include "lib.h"
#include "expath.h"
#include "getopt.h"
#include "getseq.h"
#include "hlib.h"
#include "hostable.h"
#include "import.h"
#include "uundir.h"
#include "security.h"
#include "timestmp.h"
#include "execute.h"
#ifdef _Windows
#include "winutil.h"
#include "logger.h"
#endif
/*--------------------------------------------------------------------*/
/* Global variables */
/*--------------------------------------------------------------------*/
static boolean spool_flag = FALSE;
static char spool_file[FILENAME_MAX]; // alt spool file name
static boolean dir_flag = TRUE;
static boolean xeqt_flag = TRUE; // Triggered by -r option
static char grade = 'n'; // Default grade of service
static boolean mail_me = FALSE; // changes with -m
static boolean mail_them = FALSE; // changes with -n
static char remote_user[10]; // user to mail with -n
static char *destn_file;
static char flags[16];
currentfile();
/*--------------------------------------------------------------------*/
/* u s a g e */
/* */
/* Report flags used by program */
/*--------------------------------------------------------------------*/
static void usage(void)
{
fprintf(stderr, "Usage: uucp\t[-c|-C] [-d|-f] [-gGRADE] [-j] [-m] [-nUSER] [-r] [-sFILE]\\\n\
\t\t[-xDEBUG_LEVEL] source-files destination-file\n");
}
/*--------------------------------------------------------------------*/
/* c p */
/* */
/* Copy a file */
/*--------------------------------------------------------------------*/
static int cp(char *from, char *to)
{
int fd_from, fd_to;
int nr, nw = -1;
char buf[BUFSIZ*4]; // faster if we alloc a big buffer
if ((fd_from = open(from, O_RDONLY | O_BINARY)) == -1)
return(1); // failed
/* what if the to is a directory? */
/* possible with local source & dest uucp */
if ((fd_to = open(to, O_CREAT | O_BINARY | O_WRONLY, S_IWRITE | S_IREAD)) == -1) {
close(fd_from);
return(1); // failed
/* NOTE - this assumes all the required directories exist! */
}
while ((nr = read(fd_from, buf, sizeof buf)) > 0 &&
(nw = write(fd_to, buf, nr)) == nr)
;
close(fd_to);
close(fd_from);
if (nr != 0 || nw == -1)
return(1); // failed in copy
return(0);
} /* cp */
/*--------------------------------------------------------------------*/
/* s p l i t _ p a t h */
/* */
/* split_path splits a path into 3 components. */
/* 1) The system next in line */
/* 2) Any intermediate systems as a bang path */
/* 3) The actual file name/path */
/* */
/* It tries to be a little clever with idiots, in recognizing */
/* system=this machine */
/*--------------------------------------------------------------------*/
static void split_path(char *path,
char *system,
char *inter,
char *file)
{
char *p_left, *p_right, *p;
*system = *inter = *file = '\0'; // init to nothing
for (p = path;; p = p_left + 1) {
p_left = strchr(p, '!'); // look for the first bang
if (p_left == NULL) { // not a remote path
strcpy(file, p); // so just return filename
return;
}
/* now check if the system was in fact us.
If so strip it and restart */
if (equaln(E_nodename, p, p_left - p) &&
(E_nod